<?php

namespace App\Http\Controllers\Admin;

use App\Member;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    public function index(Request $request)
    {
        return view('admin.login');
    }

    public function doLogin(Request $request)
    {
        $member = Member::where('name', '=', $request->input('name'))->first();
        if (!isset($member->id)) {
            $return = ['code' => __LINE__, 'msg' => '不存在此管理员！'];
            return response()->json($return);
        }
        if (strcmp(decrypt($member->pwd), $request->input('pwd')) != 0) {
            $return = ['code' => __LINE__, 'msg' => '管理员密码不正确！'];
            return response()->json($return);
        }
        $request->session()->put('memberId', $member->id);
        $request->session()->put('memberName', $member->name);
        $return = ['code' => 0];
        return response()->json($return);
    }
}